/**
 * Copyright &copy; 2012-2016 <a href="https://istep.lczyfz.com">Istep</a> All rights reserved.
 */
package com.lczyfz.istep.modules.teach.service;

import java.util.List;

import com.lczyfz.istep.common.constants.DeleteFlag;
import com.lczyfz.istep.modules.resource.entity.ResourcePaper;
import com.lczyfz.istep.modules.resource.entity.ResourcePaperQuestion;
import com.lczyfz.istep.modules.resource.entity.ResourceQuestion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lczyfz.istep.common.persistence.Page;
import com.lczyfz.istep.common.service.CrudService;
import com.lczyfz.istep.modules.teach.entity.TeachExam;
import com.lczyfz.istep.modules.teach.dao.TeachExamDao;

/**
 * 考试管理Service
 * @author cqh
 * @version 2017-01-12
 */
@Service
@Transactional(readOnly = true)
public class TeachExamService extends CrudService<TeachExamDao, TeachExam> {


	@Autowired
	TeachExamDao teachExamDao ;

	public TeachExam get(String id) {
		return super.get(id);
	}
	
	public List<TeachExam> findList(TeachExam teachExam) {
		return super.findList(teachExam);
	}
	
	public Page<TeachExam> findPage(Page<TeachExam> page, TeachExam teachExam) {
		return super.findPage(page, teachExam);
	}
	
	@Transactional(readOnly = false)
	public void save(TeachExam teachExam) {
		super.save(teachExam);
	}
	
	@Transactional(readOnly = false)
	public void delete(TeachExam teachExam) {
		super.delete(teachExam);
	}

	public List<ResourcePaper> findPaperList(){
		return teachExamDao.findPaperList(DeleteFlag.deleteFlag);
	}

	//根据学生ID找到分配的试卷
//	public List<TeachExam> findExamListById(String id){
//		return teachExamDao.findExamListById(id, DeleteFlag.deleteFlag);
//	}

//	public Page<TeachExam> findExamListPageById(Page<TeachExam> page, TeachExam teachExam,String id) {
//		teachExam.setPage(page);
//		page.setList(dao.findExamListById(teachExam,id, DeleteFlag.deleteFlag));
//		return page;
//	}
//	public List<TeachExam> findExamListById(String id,TeachExam teachExam) {
//		return teachExamDao.findExamListById(teachExam,id, DeleteFlag.deleteFlag);
//	}

//	public Page<TeachExam> findExamListPageById(Page<TeachExam> page, TeachExam teachExam,String userId) {
//		teachExam.setPage(page);
//		page.setList(dao.findExamListById(teachExam.getId(), userId, DeleteFlag.deleteFlag));
//		return page;
//	}
//	public List<TeachExam> findExamListById(String id) {
//		return teachExamDao.findExamListById(id, DeleteFlag.deleteFlag);
//	}

	public Page<TeachExam> findExamStuPageById(Page<TeachExam> page, TeachExam teachExam) {
		teachExam.setPage(page);
		String id = teachExam.getId();
		page.setList(teachExamDao.findExamStuById(id, teachExam));
		return page;
	}

	//我的考试-列表查询
	public Page<TeachExam> findExamListPageById(Page<TeachExam> page, TeachExam teachExam) {
		teachExam.setPage(page);
		page.setList(teachExamDao.findExamListById(teachExam));
		return page;
	}

	public List<ResourcePaper> findPaperByExamId(String id){
		return teachExamDao.findPaperByExamId(id,DeleteFlag.deleteFlag);
	}
	public List<ResourcePaperQuestion> findPaperQuestionByPaperId(String id){
		return teachExamDao.findPaperQuestionByPaperId(id,DeleteFlag.deleteFlag);
	}

	public List<ResourceQuestion> findQuesType0ByPaperId(String paperId){
		return teachExamDao.findQuesType0ByPaperId(paperId,DeleteFlag.deleteFlag);
	}


	public List<TeachExam> findTeachExamByExamId(String examId){
		return teachExamDao.findTeachExamByExamId(examId,DeleteFlag.deleteFlag);
	}

	//根据下发id和试卷id获取单条考试记录
	public TeachExam getSingleRecord(String distributeId, String paperId){
		return teachExamDao.getSingleRecord(distributeId, paperId, DeleteFlag.deleteFlag);
	}

	//我的学习任务-获取考试名称
	public List<TeachExam> stuLearnExam(String distributeId, String userId){
		return teachExamDao.stuLearnExam(distributeId, userId, DeleteFlag.deleteFlag);
	}

	//根据学生id和试卷id判断该学生之前是否下发过某场考试
	public List<TeachExam> getSingleRecordCheckExam(String paperId, String userId){
		return teachExamDao.getSingleRecordCheckExam(paperId, userId, DeleteFlag.deleteFlag);
	}

	//根据学生id获取所有下发给该学生的考试，如果某学生接受了两次下发有同样的试卷，则保留最早的考试
	//这里返回的结果也即‘我的考试’展示的列表
	public List<TeachExam> stuExamList(TeachExam teachExam){
		return teachExamDao.findExamListById(teachExam);
	}

}